package vn.anhqn.englishsentensetranslator.onlinetranslate;

import main.java.com.memetix.mst.language.Language;
import main.java.com.memetix.mst.speak.Speak;
import main.java.com.memetix.mst.translate.Translate;
import vn.anhqn.englishsentensetranslator.base.networkTask.BaseTask;
import vn.anhqn.englishsentensetranslator.constant.ConfigApp;
import vn.anhqn.englishsentensetranslator.model.TranslateModel;

public class TextTranslateTask extends BaseTask<String, TranslateModel> {
	private Language fromLang = Language.ENGLISH;
	private Language toLang = Language.ENGLISH;
	
	public TextTranslateTask(Language fromLang, Language toLanguage) {
		this.fromLang = fromLang;
		this.toLang = toLanguage;
	}
	@Override
	public TranslateModel onTaskRunning(String params) throws Exception {
		
		Translate.setClientId("AnhVietTranslate");
        Translate.setClientSecret("SKPEbWYogFDSeP+kki+VVn3xkqBd1F5mAlTn7gJkkc8=");
        Translate.setConnectionTimeout(ConfigApp.CONECTION_TIMEOUT);
        Translate.setReadTimeout(ConfigApp.READ_TIMEOUT);
        TranslateModel mTrans=null;
        String translateText = Translate.execute(params,fromLang, toLang);
        String fromSound = Speak.execute(params,ConfigApp.SPEAK_LANG);
        String toSound = Speak.execute(translateText,ConfigApp.SPEAK_LANG);
        mTrans = new TranslateModel(translateText, fromSound, toSound);
        
		return mTrans;
	}

}
